package 剑指Offer专项突破;

import java.util.*;

/**
 * Three sum
 */
public class Algo007 {
    public List<List<Integer>> threeSum(int[] nums) {
        if(nums.length<3) {
            return new ArrayList<>();
        }
        Arrays.sort(nums);
        List<List<Integer>> result = new ArrayList<>();
        int i = 0;
        while (i < nums.length-2) {
            find(nums, i, result);
            int temp = nums[i];
            while (i<nums.length && nums[i] == temp ) {
                i++;
            }
        }
        return result;
    }

    private void find(int[] nums, int i, List<List<Integer>> result) {
        int l = i+1;
        int r = nums.length-1;
        while (l<r) {
            int sum = nums[l] + nums[r] + nums[i];
            if(sum == 0) {
                result.add(Arrays.asList(nums[i], nums[l], nums[r]));
                int temp = nums[l];
                while (temp == nums[l] && l<r) {
                    l++;
                }
            }else if(sum < -nums[i]) {
                l++;
            }else {
                r--;
            }
        }
    }


    public boolean isPalindrome(String s) {
        int l = 0;
        int r = s.length()-1;
        while (l<r) {
            while (isNumber(s.charAt(l))) {}
        }
        return false;
    }

    private boolean isNumber(char c) {
        boolean a = c-'a'<26;
//        Character.isLetterOrDigit()
        return c - 'a' < 26 || c > '0';
    }
}
